//本地储存封装函数
//setStorage("useInfo", { username: "yanfang", password: "12345678" });
//1.存储
export const setStorage = (key, value) => {
  if (typeof value === "object") {
    value = JSON.stringify(value);
  }
  console.log(value);
  //直接存储value为{}[]自动转换
  window.localStorage.setItem(key, value);
};
//2.获取
export const getStorage = (key) => {
  let str = window.localStorage.getItem(key);
  try {
    str = JSON.parse(str);
  } catch (error) {
    console.log(error);
  }
  return str;
};
//3.删除
export const removeStorage = (key) => {
  window.localStorage.removeItem(key);
};
